﻿using System;
using System.Net;
using System.Net.Sockets;

namespace HslCommunication.Core.Net
{
	/// <summary>
	/// 当前的网络会话信息，还包含了一些客户端相关的基本的参数信息<br />
	/// The current network session information also contains some basic parameter information related to the client
	/// </summary>
	// Token: 0x02000145 RID: 325
	public class AppSession
	{
		/// <summary>
		/// 实例化一个构造方法
		/// </summary>
		// Token: 0x06001C6C RID: 7276 RVA: 0x0008C8D4 File Offset: 0x0008AAD4
		public AppSession()
		{
			this.ClientUniqueID = Guid.NewGuid().ToString("N");
			this.HybirdLockSend = new SimpleHybirdLock();
		}

		/// <summary>
		/// 传输数据的对象
		/// </summary>
		// Token: 0x1700058D RID: 1421
		// (get) Token: 0x06001C6D RID: 7277 RVA: 0x0008C92D File Offset: 0x0008AB2D
		// (set) Token: 0x06001C6E RID: 7278 RVA: 0x0008C935 File Offset: 0x0008AB35
		internal Socket WorkSocket { get; set; }

		// Token: 0x1700058E RID: 1422
		// (get) Token: 0x06001C6F RID: 7279 RVA: 0x0008C93E File Offset: 0x0008AB3E
		// (set) Token: 0x06001C70 RID: 7280 RVA: 0x0008C946 File Offset: 0x0008AB46
		internal SimpleHybirdLock HybirdLockSend { get; set; }

		/// <summary>
		/// IP地址
		/// </summary>
		// Token: 0x1700058F RID: 1423
		// (get) Token: 0x06001C71 RID: 7281 RVA: 0x0008C94F File Offset: 0x0008AB4F
		// (set) Token: 0x06001C72 RID: 7282 RVA: 0x0008C957 File Offset: 0x0008AB57
		public string IpAddress { get; internal set; }

		/// <summary>
		/// 此连接对象连接的远程客户端
		/// </summary>
		// Token: 0x17000590 RID: 1424
		// (get) Token: 0x06001C73 RID: 7283 RVA: 0x0008C960 File Offset: 0x0008AB60
		// (set) Token: 0x06001C74 RID: 7284 RVA: 0x0008C968 File Offset: 0x0008AB68
		public IPEndPoint IpEndPoint { get; internal set; }

		/// <summary>
		/// 远程对象的别名
		/// </summary>
		// Token: 0x17000591 RID: 1425
		// (get) Token: 0x06001C75 RID: 7285 RVA: 0x0008C971 File Offset: 0x0008AB71
		// (set) Token: 0x06001C76 RID: 7286 RVA: 0x0008C979 File Offset: 0x0008AB79
		public string LoginAlias { get; set; }

		/// <summary>
		/// 心跳验证的时间点
		/// </summary>
		// Token: 0x17000592 RID: 1426
		// (get) Token: 0x06001C77 RID: 7287 RVA: 0x0008C982 File Offset: 0x0008AB82
		// (set) Token: 0x06001C78 RID: 7288 RVA: 0x0008C98A File Offset: 0x0008AB8A
		public DateTime HeartTime { get; set; } = DateTime.Now;

		/// <summary>
		/// 客户端的类型
		/// </summary>
		// Token: 0x17000593 RID: 1427
		// (get) Token: 0x06001C79 RID: 7289 RVA: 0x0008C993 File Offset: 0x0008AB93
		// (set) Token: 0x06001C7A RID: 7290 RVA: 0x0008C99B File Offset: 0x0008AB9B
		public string ClientType { get; set; }

		/// <summary>
		/// 客户端唯一的标识
		/// </summary>
		// Token: 0x17000594 RID: 1428
		// (get) Token: 0x06001C7B RID: 7291 RVA: 0x0008C9A4 File Offset: 0x0008ABA4
		// (set) Token: 0x06001C7C RID: 7292 RVA: 0x0008C9AC File Offset: 0x0008ABAC
		public string ClientUniqueID { get; private set; }

		/// <summary>
		/// 指令头缓存
		/// </summary>
		// Token: 0x17000595 RID: 1429
		// (get) Token: 0x06001C7D RID: 7293 RVA: 0x0008C9B5 File Offset: 0x0008ABB5
		// (set) Token: 0x06001C7E RID: 7294 RVA: 0x0008C9BD File Offset: 0x0008ABBD
		internal byte[] BytesHead { get; set; } = new byte[32];

		/// <summary>
		/// 已经接收的指令头长度
		/// </summary>
		// Token: 0x17000596 RID: 1430
		// (get) Token: 0x06001C7F RID: 7295 RVA: 0x0008C9C6 File Offset: 0x0008ABC6
		// (set) Token: 0x06001C80 RID: 7296 RVA: 0x0008C9CE File Offset: 0x0008ABCE
		internal int AlreadyReceivedHead { get; set; }

		/// <summary>
		/// 数据内容缓存
		/// </summary>
		// Token: 0x17000597 RID: 1431
		// (get) Token: 0x06001C81 RID: 7297 RVA: 0x0008C9D7 File Offset: 0x0008ABD7
		// (set) Token: 0x06001C82 RID: 7298 RVA: 0x0008C9DF File Offset: 0x0008ABDF
		internal byte[] BytesContent { get; set; }

		/// <summary>
		/// 已经接收的数据内容长度
		/// </summary>
		// Token: 0x17000598 RID: 1432
		// (get) Token: 0x06001C83 RID: 7299 RVA: 0x0008C9E8 File Offset: 0x0008ABE8
		// (set) Token: 0x06001C84 RID: 7300 RVA: 0x0008C9F0 File Offset: 0x0008ABF0
		internal int AlreadyReceivedContent { get; set; }

		/// <summary>
		/// 用于关键字分类使用
		/// </summary>
		// Token: 0x17000599 RID: 1433
		// (get) Token: 0x06001C85 RID: 7301 RVA: 0x0008C9F9 File Offset: 0x0008ABF9
		// (set) Token: 0x06001C86 RID: 7302 RVA: 0x0008CA01 File Offset: 0x0008AC01
		internal string KeyGroup { get; set; }

		/// <summary>
		/// 清除本次的接收内容
		/// </summary>
		// Token: 0x06001C87 RID: 7303 RVA: 0x0008CA0A File Offset: 0x0008AC0A
		internal void Clear()
		{
			this.BytesHead = new byte[32];
			this.AlreadyReceivedHead = 0;
			this.BytesContent = null;
			this.AlreadyReceivedContent = 0;
		}

		/// <inheritdoc />
		// Token: 0x06001C88 RID: 7304 RVA: 0x0008CA34 File Offset: 0x0008AC34
		public override string ToString()
		{
			bool flag = string.IsNullOrEmpty(this.LoginAlias);
			string result;
			if (flag)
			{
				result = string.Format("AppSession[{0}]", this.IpEndPoint);
			}
			else
			{
				result = string.Format("AppSession[{0}] [{1}]", this.IpEndPoint, this.LoginAlias);
			}
			return result;
		}

		/// <summary>
		/// UDP通信中的远程端
		/// </summary>
		// Token: 0x04000628 RID: 1576
		internal EndPoint UdpEndPoint = null;
	}
}
